package src.org.jess.serv;

import java.io.IOException;

import org.codehaus.jackson.JsonGenerationException;
import org.codehaus.jackson.JsonParseException;
import org.codehaus.jackson.map.JsonMappingException;
import org.codehaus.jackson.map.ObjectMapper;

public class JsonUtil {
	private ObjectMapper objectmapper = new ObjectMapper();
	
	public Object json2Obj(String str,Class clazz){
		Object object = null;
		System.out.println("I am in json");
		try {
			System.out.println(objectmapper.readValue("{\"type\":0,\"from\":\"111\",\"to\":1,\"content\":1}", MessageVo.class));
			object = objectmapper.readValue(str,clazz);
		} catch (JsonParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (JsonMappingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return object;		
	}
	public String obj2Json(Object obj){
		String str = null;
		try {
			str = objectmapper.writeValueAsString(obj);
		} catch (JsonGenerationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (JsonMappingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return str;
	}
}
